<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for Signature.init() of 'crypto.js'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>

<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// 1. DATA FOR PRIVATE KEY TEST

// 1.1. Plain PKCS#8 Private Key

// _test/z1.prv.p8p.pem (RSA)
var z1PrvP8PPEM = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEA6GZN0rQFKRIVaPOz\n" +
"m8l6Yue6PAm6vcTw3NjfkOt5C5u2RaK3DjESdHtNPEG1FCSJURX++I951D6uWxpO\n" +
"NRj9WQIDAQABAkB4u8VMZGeV6aYjyw+RLH+faGFxFWDle63iHe0vfZV5+GJy+rnn\n" +
"GrJygsJ2DEBNrmrIo6uFLPa81WL5r/gkeiZNAiEA/pvUUIZrMlVhT96XanasCx1Y\n" +
"MN2mT1NZuUbYUSvBI58CIQDpq2gPXwXbsPQxGw5vQ2j0h0oSOJedi8YAw1xvIHB8\n" +
"BwIhANVJy2mNwX1P4w5ahPOt6GADPB7rf2fShkZcn9gX1Fs3AiAYSbS7REk7mJ0J\n" +
"LaLGdd9G63kLg85eldSy55uIAXsvqQIgfSYaliVtSbAgyx1Yfs3hJ+CTpNKzTNv/\n" +
"Fx80EltYV6k=\n" +
"-----END PRIVATE KEY-----\n";

// _gitpg/jsrsasign/test/eckey/k1.prv.p8p.pem (ECC)
var k1PrvP8PPEM = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgEbVzfPnZPxfAyxqE\n" +
"ZV05laAoJAl+/6Xt2O4mOB611sOhRANCAASgFTKjwJAAU95g++/vzKWHkzAVmNMI\n" +
"tB5vTjZOOIwnEb70MsWZFIyUFD1P9Gwstz4+akHX7vI8BH6hHmBmfeQl\n" +
"-----END PRIVATE KEY-----\n";

// 1.2. Plain PKCS#5 Private Key

// _test/z1.prv.p5p.pem (RSA)
var z1PrvP5PPEM = "" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIBOgIBAAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E8NzY35DreQubtkWitw4x\n" +
"EnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQJAeLvFTGRnlemmI8sPkSx/\n" +
"n2hhcRVg5Xut4h3tL32Vefhicvq55xqycoLCdgxATa5qyKOrhSz2vNVi+a/4JHom\n" +
"TQIhAP6b1FCGazJVYU/el2p2rAsdWDDdpk9TWblG2FErwSOfAiEA6atoD18F27D0\n" +
"MRsOb0No9IdKEjiXnYvGAMNcbyBwfAcCIQDVSctpjcF9T+MOWoTzrehgAzwe639n\n" +
"0oZGXJ/YF9RbNwIgGEm0u0RJO5idCS2ixnXfRut5C4POXpXUsuebiAF7L6kCIH0m\n" +
"GpYlbUmwIMsdWH7N4Sfgk6TSs0zb/xcfNBJbWFep\n" +
"-----END RSA PRIVATE KEY-----\n";

// 1.3. Encrypted PKCS#5 Private Key

// _test/z1.prv.p5e.pem (RSA)
var z1PrvPemP5E = "" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"Proc-Type: 4,ENCRYPTED\n" +
"DEK-Info: DES-EDE3-CBC,4626F2E5853E783F\n" +
"\n" +
"3vFpkrnbantC8RSzng2+jBw/VX95oi0VGKP0G8whENHUOVQXB/YOUSj+n80Y0Wwc\n" +
"GpeQi8U0FQdWyYv8b9aioeFB06r9t9mJsYscJ/wcIvv5tTMkr89cwN3+4GQQuqNg\n" +
"TmI9ekeoZ3NP26hTM4XTuFqHx4dzNNwjDLc8txc77WE/o4J4p8k9Py5yPZjs9EKy\n" +
"wy/yxtqQYQuFj90OMEG1G89iHTZRcq4YTZYdqg6P/XEUvyjifN+7Nym8f2N9TDDn\n" +
"RJtApPQlrgXvUDQKz6Lu1ZYMwe94E9YdutDGQMbxixbiyxlcxrkb/oEHH5WP5qPG\n" +
"w/xzh08Ce2Ftba2Q860S8nznjyZFiv+lqSKBahbujgP/63ZL+JbAd4cYBqgm4g1C\n" +
"YwMhHJbaVCzwYduxdyK2JBYEosDZiDfnOP4DqPhJYpg=\n" +
"-----END RSA PRIVATE KEY-----\n";
var z1PrvPemP5EPass = "hoge";

// 1.4. Encrypted PKCS#8 Private Key

// _test/z1.prv.p8e.pem (RSA)
var z1PrvPemP8E = "" +
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n" +
"MIIBpjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIyScsGkpMl3kCAggA\n" +
"MBQGCCqGSIb3DQMHBAiObBK7oyBAzwSCAWCkStExnU3pYBQAxRqDctg5QEO3Ic1d\n" +
"GsRW+JW0kNonUydoOSD/7DBglnSDowiQ69HCW4OmumSJIU0hewX0yburFuy6Zs/q\n" +
"DkWox7oxBCsgFmfmkKGcK0USeJ+LX+YZVbvCCvHZkd99pEqQSfkRu4DgXbWmo6Zv\n" +
"2A6VFyBhE9MFmYex8mHTZ5cchBzAiFWRzjpRX94F4vbUFoXPGrEbOLovM2VpZ8Df\n" +
"1nLuXhWYVHsXHWn+fm7TH4Xzh1mFYYkTiXL9ABwKKohEL2SQJzKpa9FZvOZAmlSe\n" +
"UgQxVQLM/ZC+o4Vs4JHqIu4Ek2bgjEqDzo2EPznpcCsQTcwOqhPwNjP4Y3ovn1Nm\n" +
"8i0Hx51OA0vjRZBvvduKM9d5kRAOg8jqLjeWU3KraWLuSJ96RTzlWFgw6PsML+RE\n" +
"LHfdKDjRT0NMEMRh892oBi828asvvSWO6HYcM0xclt0uakxJhVP/mtzA\n" +
"-----END ENCRYPTED PRIVATE KEY-----\n";
var z1PrvPemP8EPass = "passwd";

// _gitpg/jsrsasign/test/eckey/k1.prv.p8e.pem pass:passwd
var k1PrvPemP8E = "" +
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n" +
"MIHVMEAGCSqGSIb3DQEFDTAzMBsGCSqGSIb3DQEFDDAOBAj20JdDrZ2aywICCAAw\n" +
"FAYIKoZIhvcNAwcECMUYjGnyWlEZBIGQlK5TFonZXOFuu+UGi9VvH399ps4QHRe5\n" +
"ddRaWYUvjnKoA1kR8NorNzpAxwFeC0tGC9FHs8EV8gE1kCRJS0TBfn9Z3N/I+FEo\n" +
"s6qwahGeiHVJZQc6sHg8ch/At80D+2EpuQDhL/DYPYzDcxema7QE3gi0Q6rEuxgv\n" +
"1yqXRRTZGKyiNjmozXY/F0G6OQsT8BlA\n" +
"-----END ENCRYPTED PRIVATE KEY-----\n";
var k1PrvPemP8EPass = "passwd";

// 2. DATA FOR PUBLIC KEY TEST

// _test/z1 (RSA)
var z1PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E\n" +
"8NzY35DreQubtkWitw4xEnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQ==\n" +
"-----END PUBLIC KEY-----\n";

// _gitpg/jsrsasign/test/eckey/k1.pub.pem (ECC)
var k1PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" + 
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjT\n" + 
"CLQeb042TjiMJxG+9DLFmRSMlBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==\n" + 
"-----END PUBLIC KEY-----\n";

// _test/z1.cer (RSA)
var z1CertPEM = "" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIBdTCCAR+gAwIBAgIBBTANBgkqhkiG9w0BAQUFADAaMQswCQYDVQQGEwJVUzEL\n" +
"MAkGA1UECgwCYTEwHhcNMTMwNTA0MDM0MTQxWhcNMjMwNTA0MDM0MTQxWjAaMQsw\n" +
"CQYDVQQGEwJVUzELMAkGA1UECgwCYTEwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA\n" +
"6GZN0rQFKRIVaPOzm8l6Yue6PAm6vcTw3NjfkOt5C5u2RaK3DjESdHtNPEG1FCSJ\n" +
"URX++I951D6uWxpONRj9WQIDAQABo1AwTjAdBgNVHQ4EFgQUxUc+4gDI561wA9/1\n" +
"QguM3fTCDhUwHwYDVR0jBBgwFoAUxUc+4gDI561wA9/1QguM3fTCDhUwDAYDVR0T\n" +
"BAUwAwEB/zANBgkqhkiG9w0BAQUFAANBALL2k69LjwOYfDXv3TXJUAFGUqto+Noj\n" +
"CJLP08fOfNBZy+KAIy0GsrNU/3uRViqbuGqAnH9kFFwHQjOAFrAe8XQ=\n" +
"-----END CERTIFICATE-----\n";

// _gitpg/jsrsasign/test/eckey/k1.self.cer
var k1CertPEM = "" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIBfDCCASGgAwIBAgIJAKbxELQvSUDNMAoGCCqGSM49BAMCMBoxCzAJBgNVBAYT\n" +
"AlVTMQswCQYDVQQKDAJLMTAeFw0xMzA3MTQwMjE3MTdaFw0yMzA3MTIwMjE3MTda\n" +
"MBoxCzAJBgNVBAYTAlVTMQswCQYDVQQKDAJLMTBZMBMGByqGSM49AgEGCCqGSM49\n" +
"AwEHA0IABKAVMqPAkABT3mD77+/MpYeTMBWY0wi0Hm9ONk44jCcRvvQyxZkUjJQU\n" +
"PU/0bCy3Pj5qQdfu8jwEfqEeYGZ95CWjUDBOMB0GA1UdDgQWBBTIR74yfMz/Y4hw\n" +
"dXSW4r42bESo/DAfBgNVHSMEGDAWgBTIR74yfMz/Y4hwdXSW4r42bESo/DAMBgNV\n" +
"HRMEBTADAQH/MAoGCCqGSM49BAMCA0kAMEYCIQDfAcS/WKBrP6JBgksQVpp4jdq4\n" +
"C53Yu4F5NkaMgthAHgIhANGRdWAP1QdW9l6tiglQwdqJs4T0e8+NYv+RcAb3VYwn\n" +
"-----END CERTIFICATE-----\n";

// 3. Priavte Key Test

// 3.1. Plain PKCS#8 Private Key Test (RSA,ECC)

test("sign init plain PKCS#8 Private Key PEM(RSA)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig.init(z1PrvP8PPEM);
  equal(sig.state, "SIGN");
});

test("sign init plain PKCS#8 Private Key PEM(ECC)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
  sig.init(k1PrvP8PPEM);
  equal(sig.state, "SIGN");
});

// 3.2. Plain PKCS#5 Private Key Test (RSA)

test("sign init plain PKCS#5 Privae Key PEM(RSA)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig.init(z1PrvP5PPEM);
  equal(sig.state, "SIGN");
});

// 3.3. Encrypted PKCS#5 Private Key Test (RSA)

test("sign init encrypted PKCS#5 Privae Key PEM(RSA)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig.init(z1PrvPemP5E, z1PrvPemP5EPass);
  equal(sig.state, "SIGN");
});

// 3.4. Encrypted PKCS#8 Private Key Test (RSA,ECC)

test("sign init encrypted PKCS#8 Privae Key PEM(RSA)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig.init(z1PrvPemP8E, z1PrvPemP8EPass);
  equal(sig.state, "SIGN");
});

test("sign init encrypted PKCS#8 Privae Key PEM(ECC) pretest(key loading)", function() {
  var key = KEYUTIL.getKey(k1PrvPemP8E, k1PrvPemP8EPass);
  expect(2);
  equal(key.type, "EC", "type");
  ok(key.isPrivate, "isPrivate");
});

test("sign init encrypted PKCS#8 Privae Key PEM(ECC)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
  sig.init(k1PrvPemP8E, k1PrvPemP8EPass);
  equal(sig.state, "SIGN");
});

// 4. Public Key Test

// PKCS#8 Public Key Test (RSA,ECC)
test("verify init PKCS#8 Public Key PEM(RSA)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig.init(z1PubPemP8);
  equal(sig.state, "VERIFY");
});

test("verify init PKCS#8 Public Key PEM(ECC)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
  sig.init(k1PubPemP8);
  equal(sig.state, "VERIFY");
});

// Certificate Test (RSA,ECC)
test("verify init CertPEM(RSA)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig.init(z1CertPEM);
  equal(sig.state, "VERIFY");
});

test("verify init CertPEM(ECC)", function() {
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
  sig.init(k1CertPEM);
  equal(sig.state, "VERIFY");
});

// Public Key Object Test (RSA,ECC)
test("verify init key object(RSA)", function() {
  var pubKey = X509.getPublicKeyFromCertPEM(z1CertPEM);
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig.init(pubKey);
  equal(sig.state, "VERIFY");
});

test("verify init key object(ECC)", function() {
  var pubKey = X509.getPublicKeyFromCertPEM(k1CertPEM);
  var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
  sig.init(pubKey);
  equal(sig.state, "VERIFY");
});

// 5. Sign and Verify Integrated Test

test("sign and verify integrated test (RSA)", function() {
  var sig1 = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig1.init(z1PrvP8PPEM);
  sig1.updateString("aaa");
  var hSigVal = sig1.sign();

  var sig2 = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
  sig2.init(z1CertPEM);
  sig2.updateString("aaa");

  equal(sig2.verify(hSigVal), true, "t1");
});

test("sign and verify integrated test (ECC)", function() {
  var sig1 = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
  sig1.init(k1PrvP8PPEM);
  sig1.updateString("aaa");
  var hSigVal = sig1.sign();

  var sig2 = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
  sig2.init(k1CertPEM);
  sig2.updateString("aaa");

  equal(sig2.verify(hSigVal), true, "t1");
});

test("sign and verify integrated test (RSAPSS)", function() {
  var sig1 = new KJUR.crypto.Signature({'alg': 'SHA1withRSAandMGF1'});
  sig1.init(z1PrvP8PPEM);
  sig1.updateString("aaa");
  var hSigVal = sig1.sign();

  var sig2 = new KJUR.crypto.Signature({'alg': 'SHA1withRSAandMGF1'});
  sig2.init(z1CertPEM);
  sig2.updateString("aaa");

  equal(sig2.verify(hSigVal), true, "t1");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>

<p>
ECC related QUnit test pages: 
<a href="qunit-do-crypto.html">crypto.js</a> | 
<a href="qunit-do-crypto-ecdsa.html">crypto.js Signature class for ECDSA</a> | 
<a href="qunit-do-ecdsamod.html">ecdsa-modified.js</a> | 
<a href="qunit-do-ecparam.html">ecparam.js</a> | 
</p>

</body>
</html>

